import 'package:hc_bot_kit/state.dart';
import 'package:permission_handler/permission_handler.dart';

import 'hc_bot_kit_platform_interface.dart';

class HcBotKit {

  Stream<GuideState>? get stateStream => HcBotKitPlatform.instance.controller?.stream;

  Future connect(String ipAddress) async {
   await HcBotKitPlatform.instance.connect(ipAddress);
  }

  Future close(String ipAddress) async {
    await HcBotKitPlatform.instance.close();
  }

  Future<List<String>> fetchAllPoints() async {
    return HcBotKitPlatform.instance.fetchAllPoints();
  }

  Future startGuide(String dst) async {
    await Permission.storage.request();
    var status = await Permission.storage.status;
    if (!status.isGranted) {
      return Future.error("请授予存储权限");
    }
    final ret = await HcBotKitPlatform.instance.guide(dst);
    if (!ret) {
      return Future.error("启动导航失败");
    }
  }
}
